<template>
  <div class="child1">
    <h3>子组件1</h3>
	<h4>子组件1有电脑：{{ computer }}</h4>
	<h4 v-show="receivedToy">子组件收到玩具：{{ receivedToy }}</h4>

  </div>
</template>

<script setup lang="ts" name="Child1">
	import {ref} from 'vue'
	const computer = ref('电脑')
	// import mitt from 'mitt'//文件在utils中声明暴露，错误的引入
	//共同的emitter实例早已在utils文件中无需创建
	import emitter from "@/utils/emitter.ts"
	let receivedToy = ref('')
	// 给按钮添加点击事件
	emitter.on('send-toy',(toy:any) => {
		receivedToy.value = toy
	})

</script>

<style scoped>
	.child1{
		margin-top: 50px;
		background-color: skyblue;
		padding: 10px;
		box-shadow: 0 0 10px black;
		border-radius: 10px;
	}
	.child1 button{
		margin-right: 10px;
	}
</style>